@extends('layouts.app')

@section('title', $topic->title)

@section('keyword', $topic->str_tags)

@section('description', $topic->excerpt)

@section('content')

    <div class="row">

        <div class="col-lg-3 col-md-3 hidden-sm hidden-xs author-info">
            <div class="card ">
                <div class="card-body">
                    <div class="media">
                        <div align="center">
                            <a href="{{ route('users.show', $topic->user->id) }}">
                                <img class="thumbnail img-fluid" src="{{ $topic->user->avatar }}" width="300px"
                                     height="300px">
                            </a>
                        </div>
                    </div>
                    <hr>
                    <div class="text-center">
                        <a class="media mt-2 text-secondary" href="{{ route('users.show', $topic->user_id) }}">
                            作者：{{ $topic->user->name }}
                        </a>
                        <p class="media mt-2 text-secondary" title="{{  $topic->user->last_actived_at }}">活跃：{{ $topic->user->last_actived_at->diffForHumans() }}</p>
                    </div>
                </div>
            </div>

            @include('topics._sidebar')
        </div>

        <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12 topic-content">
            <div class="card ">
                <div class="card-body p-0">
                    <h1 class="text-center mt-3 mb-3">
                        {{ $topic->title }}
                    </h1>

                    <div class="article-meta text-center text-secondary">
                        {{ $topic->created_at->diffForHumans() }}
                        ⋅
                        <i class="far fa-comment"></i>
                        {{ $topic->reply_count }}
                        ⋅
                        <i class="far fa-eye"></i>
                        {{ $topic->view_count }}
                    </div>

                    <div id="topic-body-md" class="topic-body mt-4 mb-4">
                        <textarea class="d-none">{!! $topic->body !!}</textarea>
                    </div>


                    @can('update', $topic)
                        <div class="operate">
                            <hr>
                            <a href="{{ route('topics.edit', $topic->id) }}" class="btn btn-outline-secondary btn-sm"
                               role="button">
                                <i class="far fa-edit"></i> 编辑
                            </a>
                            <form action="{{ route('topics.destroy', $topic->id) }}" method="post"
                                  style="display: inline-block;"
                                  onsubmit="return confirm('您确定要删除吗？');">
                                {{ csrf_field() }}
                                {{ method_field('DELETE') }}
                                <button type="submit" class="btn btn-outline-secondary btn-sm">
                                    <i class="far fa-trash-alt"></i> 删除
                                </button>
                            </form>
                        </div>
                    @endcan

                </div>
            </div>


            {{-- 用户回复列表 --}}
            <div class="card topic-reply mt-2">
                <div class="card-body">
                    @includeWhen(\Illuminate\Support\Facades\Auth::check(), 'topics._reply_box', ['topic' => $topic])

                    @if(!\Illuminate\Support\Facades\Auth::check())
                        <div class="d-flex justify-content-center">
                            <a href="{{ route('login') }}" class="px-1 text-blue">登录</a>
                        </div>
                    @endif

                    @include('topics._reply_list', ['replies' => $topic->replies()->with('user')->get()])
                </div>
            </div>

        </div>
    </div>

@stop

@section('styles')
    <link rel="stylesheet" href="{{ asset('/vendor/editor.md/css/editormd.preview.min.css') }}"/>

@stop

@section('scripts')
    <script src="{{ asset('/vendor/editor.md/editormd.min.js') }}"></script>
    <script src="{{ asset('/vendor/editor.md/lib/flowchart.min.js') }}"></script>
    <script src="{{ asset('/vendor/editor.md/lib/jquery.flowchart.min.js') }}"></script>
    <script src="{{ asset('/vendor/editor.md/lib/marked.min.js') }}"></script>
    <script src="{{ asset('/vendor/editor.md/lib/prettify.min.js') }}"></script>
    <script src="{{ asset('/vendor/editor.md/lib/raphael.min.js') }}"></script>
    <script src="{{ asset('/vendor/editor.md/lib/sequence-diagram.min.js') }}"></script>
    <script src="{{ asset('/vendor/editor.md/lib/underscore.min.js') }}"></script>

    <script>

        $(function () {

            // 修正emoji图片错误
            editormd.emoji = {
                path: "//staticfile.qnssl.com/emoji-cheat-sheet/1.0.0/",
                ext: ".png"
            };
            var topicEditorMdView = editormd.markdownToHTML("topic-body-md", {
                // markdown : md,
                codeFold: true,
                syncScrolling: true,
                saveHTMLToTextarea: true,    // 保存 HTML 到 Textarea
                searchReplace: true,
                watch: true,                // 关闭实时预览
                htmlDecode: "style,script,iframe|on*",            // 开启 HTML 标签解析，为了安全性，默认不开启
                previewCodeHighlight: true, // 关闭预览 HTML 的代码块高亮，默认开启
                emoji: true,
                taskList: true,
                tocm: true,                  // Using [TOCM]
                tex: true,                   // 开启科学公式TeX语言支持，默认关闭
                flowChart: true,             // 开启流程图支持，默认关闭
                sequenceDiagram: true,       // 开启时序/序列图支持，默认关闭,
            });

        });
    </script>

@stop

